<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="生态箱号" prop="caseNumber">
        <el-select v-model="queryParams.caseList" multiple placeholder="请选择">
          <el-option
            v-for="dict in dict.type.qs_case_number"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="周选择" prop="createTime">
        <el-date-picker
          v-model="cheakWeek"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="week"
          format="yyyy 第 WW 周"
          placeholder="选择周"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <!-- <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['realTimeInformation:realTimeInformation:export']"
        >导出</el-button> -->
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <div class="chart-wrapper">
      <bar-chart :chart-data="barChartData" />
    </div>
     <el-table v-loading="loading" :data="realTimeInformationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="箱号" align="center" prop="caseNumber" />
      <el-table-column label="周" align="center" prop="weekOfYear" width="180"/>
      <el-table-column label="出料实际值(g)" align="center" prop="finishedWeight" />
      <el-table-column label="投料盒数" align="center" prop="feedBoxNum" />
      <el-table-column label="投虫盒数" align="center" prop="wormBoxNum" />
      <el-table-column label="翻盒盒数" align="center" prop="finishedBoxNum" />
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
  </div>
</template>

<script>
import {
  getBarChartsData
} from "@/api/realTimeInformation/realTimeInformation";
import BarChart from '../../dashboard/BarChart'
const barChartData = {
 
}
export default {
  name: "statistics",
  dicts: ['qs_case_number'],
  components: {
    BarChart
  },
  data() {
    return {
        // 显示搜索条件
      showSearch: true,
       // 总条数
      total: 0,
      cheakWeek:'',
      // 遮罩层
      loading: true,
      realTimeInformationList:[],      
      barChartData: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: [],
        caseList:["1"]
      },
      barChartData:[]
     
    };
  },
  created() {
    this.getList();
  },
  
  methods: {
      /** 查询RealTimeInformation列表 */
    getList() {
      this.loading = true;
      this.queryParams.startTime = this.cheakWeek;
      getBarChartsData(this.queryParams).then(response => {
        this.barChartData = response.data.barChartsData;
        this.realTimeInformationList = response.data.realTimeInformationListStatistics;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
     // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('realTimeInformation/realTimeInformation/export', {
        ...this.queryParams
      }, `realTimeInformation_${new Date().getTime()}.xlsx`)
    },
     handleSetbarChartData(type) {
      this.barChartData = barChartData[type]
    }
  }
};
</script>
<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
